1 package tw.com.javaworld.CH15;
2 
3 import javax.servlet.jsp.*;
4 import javax.servlet.jsp.tagext.*;
5 
6 public class Myfont extends TagSupport {
7 
8     private String bgColor = "#FFFFFF"; // 預設值:白色  
9     private String color = "#000000"; // 字體預設黑色  
10    private String align = "CENTER"; // 預設居中  
11    private String fontSize = "3"; // 字體大小預設3  
12    private String border = "0"; // 表格邊寬預設為0  
13    private String width = null; // 表格寬度為 null  
14    private String bordercolor = "#000000"; // 表格邊寬顏色,預設黑色  
15
16    public void setBgColor(String newBgColor) {
17        bgColor = newBgColor;
18    }
19    public void setColor(String newColor) {
20        color = newColor;
21    }
22    public void setAlign(String newAlign) {
23        align = newAlign;
24    }
25    public void setFontSize(String newFontSize) {
26        fontSize = newFontSize;
27    }
28    public void setBorder(String newBorder) {
29        border = newBorder;
30    }
31    public void setWidth(String newWidth) {
32        width = newWidth;
33    }
34    public void setBordercolor(String newBordercolor) {
35        bordercolor = newBordercolor;
36    }
37    
38    public int doStartTag() {
39        try {
40            JspWriter out = pageContext.getOut();
41            out.print("<table border=" + border + " bordercolor=" + bordercolor);
42            if (width != null) {
43                out.print(" WIDTH=\"" + width + "\" >");
44            }
45            out.print("><TD bgcolor=" + bgColor + ">");
46            out.print("<div align=" + align + "><font size=" + fontSize + " color=" + color + "> ");
47        } catch (Exception e) {
48            System.out.println("Error in doStartTag of Myfont Handler Class: " + e);
49        }
50        return (EVAL_BODY_INCLUDE); 
51    }
52    
53    public int doEndTag() {
54        try {
55            JspWriter out = pageContext.getOut();
56            out.print("</td></tr></table>");
57        } catch (Exception e) {
58            System.out.println("Error in doEndTag of Myfont Handler Class: " + e);
59        }
60        return (EVAL_PAGE);
61        
62    }
63}